@extends('layouts.app')

@section('content')
    <div class="container mt-3">
        <div class="row justify-content-center">
            <div class="col-md-12">
                    <div class="tab-container">
                        <ul role="tablist" class="nav nav-tabs">
                            <li class="nav-item"><a href="/store" class="nav-link active">店铺列表</a></li>
                            <li class="nav-item"><a href="/store/create" class="nav-link">添加店铺</a></li>
                        </ul>
                        <div class="card card-contrast card-border-color-success">
                            <div class="card-body">
                                <table class="table table-responsive" style="white-space:nowrap;">
                                    <thead>
                                    <tr>
                                        <th style="width: 5%;">编号</th>
                                        <th style="10%">店铺名称</th><th>所属分类</th><th>店铺封面</th>
                                        <th>店铺状态</th>
                                        <th>创建时间</th>
                                        <th>&nbsp;</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($data as $d)
                                        <tr>
                                            <td>{!! $d['id'] !!}</td>
                                            <td>{!! $d['name'] !!}</td><td>{!! $d->cate->cname !!}</td><td><img src='{!! $d['face'] !!}' style='width:45px;height:45px;'/></td><td>@if($d['status'])正常@else待审核@endif</td>
                                            <td>{!! $d['created_at'] !!}</td>
                                            <td class="text-right">
                                                <a href="/store/{{$d['id']}}/edit" class="btn btn-secondary">编辑</a>
                                                <button type="button" class="btn btn-secondary btn-danger" onclick="del({{$d['id']}},this)">删除</button>
                                                <form action="/store/{{$d['id']}}" hidden method="post">
                                                    @csrf @method('DELETE')
                                                </form>
                                            </td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                <div class="float-right">
                </div>
            </div>
        </div>
    </div>
@endsection
@section('scripts')
    <script>
        function del(id, el) {
            if (confirm('确定删除吗？')) {
                $(el).next('form').trigger('submit')
            }
        }
    </script>
@endsection
